package main

import (
	"fmt"
	"sync"
	"time"
)

var wg sync.WaitGroup

func consumer(queue <-chan int) {
	defer wg.Done()
	for {
		data, ok := <-queue
		if !ok {
			break
		}
		fmt.Println(data)
		time.Sleep(time.Second)
	}
}

func main() {
	// 有没有缓冲 1. 有缓冲 2. 无缓冲
	// 双向的还是单向的,	为了安全, 提供了单向channel
	var msg chan int
	msg = make(chan int)
	wg.Add(1)
	go consumer(msg)
	msg <- 1 // 将1放入channel

	close(msg)
	wg.Wait()
}
